package com.leet.code.simple_array;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: WYG
 * @time: 2020/12/31 11:16
 */

public class ArrayRankTransform {

    public int[] arrayRankTransform(int[] arr) {
        int length = arr.length;
        int[] new_arr = new int[length];
        for (int i = 0; i < length; i++) {
            new_arr[i] = arr[i];
        }
        Arrays.sort(new_arr);
        Map<Integer, Integer> map = new HashMap<>();
        int temp = 0;
        for (int i = 0; i < length; i++) {
            if (!map.containsKey(new_arr[i])) {
                map.put(new_arr[i], i + 1 + temp);
            } else {
                temp--;
            }
        }
        for (int i = 0; i < length; i++) {
            new_arr[i] = map.get(arr[i]);
        }
        return new_arr;
    }

}
